package abel.wlmr.model.type;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 终端故障编码 故障
 * 1 终端主板内存故障
 * 2 时钟故障
 * 3 主板通信故障
 * 4 485 抄表故障
 * 5 显示板故障
 * 6 载波通道异常
 * 7 M_BUS 通信故障
 * 8 无线通讯故障
 * 8-255 备用
 * 
 * @author Abel
 *
 */
public enum TermErrorType {
    MainboardMemory(1),
    Clock(2),
    MainboardComm(3),
    Rs485Reading(4),
    Display(5),
    Carrier(6),
    MbusComm(7),
    Wireless(8),
    Reserved(9);

    private short value;

    private static final Map<Short, TermErrorType> map;

    static {
        HashMap<Short, TermErrorType> map1 = new HashMap<>();
        for (TermErrorType fd : TermErrorType.values()) {
            map1.put(fd.value, fd);
        }

        map = Collections.unmodifiableMap(map1);
    }

    private TermErrorType(int v) {
        this.value = (short) v;
    }

    public static TermErrorType findEnumByValue(int v) {
        short key = (short) v;
        if (map.containsKey(key)) {
            return map.get(key);
        }

        Reserved.value = (short) v;
        return TermErrorType.Reserved;
    }

    /* (non-Javadoc)
     * @see java.lang.Enum#toString()
     */
    @Override
    public String toString() {
        return String.format("TermErrorType[value=%s]", value);
    }

    /**
     * @return the value
     */
    public short getValue() {
        return value;
    }

    /**
     * @param value
     *            the value to set
     */
    public void setValue(short value) {
        this.value = value;
    }
}
